package com.bdqn.t330.ch06.controller;

import com.bdqn.t330.ch06.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(Model model) {
        model.addAttribute("message", "hello T330");
        return "demo/hello";
    }

    @RequestMapping("/user")
    public String user(Model model) {
        User user = new User();
        user.setUsrId(1L);
        user.setUsrName("张三");
        model.addAttribute("user", user);
        return "/demo/hello";
    }

    @GetMapping(value = "/string")
    public String getString(Model model, HttpServletRequest request) {//演示赋值、字符串拼接
        model.addAttribute("userName", "ktjiaoyu");
        request.setAttribute("test", "request");
        request.getSession().setAttribute("test", "session");
        model.addAttribute("date", new Date());
        return "demo/string";
    }


    @GetMapping(value = "/index")
    public String index() {
        return "/demo/index";
    }


    @GetMapping(value = "/fragment")
    public String fragment() {
        return "/demo/fragment";
    }

}
